package 草稿包;

import javax.lang.model.type.IntersectionType;
import java.util.*;

public class test2 {
        static public int[] intersection(int[] nums1, int[] nums2) {
        List<Integer> ans=new ArrayList<>();
        Set<Integer> set=new HashSet<>();
        for(int i=0;i<nums1.length;i++){
            set.add(nums1[i]);
        }
        for(int i=0;i<nums2.length;i++){
            if(set.contains(nums2[i])){
                ans.add(nums2[i]);
            }
        }

            Object[] objects =ans.toArray();
            int[] res=new int[objects.length];
            for(int i=0;i<objects.length;i++){
                res[i]=((Integer)objects[i]).intValue();
            }
            System.out.println(Arrays.toString(res));
            return null;
    }
    public static void main(String[] args) {
            int[] a={1,2,3,4};
            int[] b={1,2,4};
        intersection(a,b);
        System.out.println("Hello,World!");
    }
}
